package com.mzba.easy.weibo.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.util.Log;

/**
 * 日期时间工具类，用于格式化处理微博日期时间字段
 * 
 * @author 06peng
 *
 */
public class DateUtil {
	
	public static SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm"); 

	@SuppressWarnings("deprecation")
	public static String getCreateAt(String srcDate) {
		if (srcDate == null) {
			return "未知";
		}
		String destDate = "";
		try {
			Date date = null;
			if (srcDate.length() == 30) {
				date = new Date(srcDate);
			} else {
				Log.e("DateUtil", "Date format is incorrect, the invalid value is: " + srcDate);
				return srcDate;
			}
			
			long now = System.currentTimeMillis();
			Long seconds = (now - date.getTime()) / 1000;
			
			long days = seconds / (24 * 60 * 60);
			long hours = seconds / (60 * 60);
			long minutes = seconds / 60;
			
			if (days > 0) {
				destDate = sdf.format(date);
			} else if (hours > 0) {
				destDate = hours + "小时前";
			} else if (minutes > 0) {
				destDate = minutes + "分钟前";
			} else {
				destDate = "刚刚";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return destDate;
	}
}
